<script setup>
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'
const props = defineProps({
  name: {
    type: String,
    required: true
  }
})
// 定义点击事件处理函数
const onClickLeft = () => {
  if (props.name === '看课件' || props.name === '看需求') {
    return router.push('/')
  }
  if (props.name === '课件详情') {
    return router.go(-1)
  }
  if (props.name === '需求详情') {
    return router.go(-1)
  }
  if (props.name === '积分详情' || '积分查询') {
    return router.go(-1)
  }
  return router.push('/')
}

const router = useRouter()
</script>
<template>
  <div class="navbar">
    <van-nav-bar v-if="name === '首页'" :title="name" />
    <van-nav-bar v-else :title="name" left-text="返回" left-arrow @click-left="onClickLeft" />
  </div>
</template>
<style>
/* 添加这段样式后，Primary Button 会变成红色 */
:root:root {
  --van-nav-bar-title-font-size: 1.2rem;
  --van-nav-bar-arrow-size: 1.2rem;
}
</style>
